package com.atguigu.controller;

import com.atguigu.entity.Dict;
import com.atguigu.result.Result;
import com.atguigu.service.DictService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dict")
public class DictController {

    @DubboReference
    private DictService dictService;

    //完成查询字典数据
    @GetMapping("/findListByParentDictCode/{parentDictCode}")
    public Result findListByParentDictCode(@PathVariable("parentDictCode") String parentDictCode) {
        //调用业务层方法根据父节点dictCode查询子节点列表
        List<Dict> dictList = dictService.findListByParentDictCode(parentDictCode);
        return Result.ok(dictList);
    }


    //根据区域id查询该区域所有板块
    @GetMapping("/findListByParentId/{parentId}")
    public Result findListByParentId(@PathVariable("parentId") Long parentId) {
        //调用业务层方法更具父节点的id查询子节点的列表
        List<Dict> dictList = dictService.findListByParentId(parentId);
        return Result.ok(dictList);
    }
}
